package com.woniuxy.ams.service.impl;

import com.woniuxy.ams.dao.CompanyTemplate2DeptDao;
import com.woniuxy.ams.entity.CompanyTemplate;
import com.woniuxy.ams.entity.CompanyTemplate2Dept;
import com.woniuxy.ams.entity.Dept;
import com.woniuxy.ams.service.ICompanyTemplate2DeptService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * 模板对应部门service层
 */
@Service
public class CompanyTemplate2DeptServiceImpl implements ICompanyTemplate2DeptService {

    /**
     * 注入dao
     */
    @Resource
    CompanyTemplate2DeptDao companyTemplate2DeptDao;

    /**
     * 新增模板对应部门
     * @param template2DeptList
     * @return int
     */
    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int addTemplate2Dept(List<CompanyTemplate2Dept> template2DeptList) {
        return companyTemplate2DeptDao.addTemplate2Dept(template2DeptList);
    }

    /**
     * 查询所有模板对应部门
     * @return List<CompanyTemplate2Dept>
     */
    @Override
    public List<CompanyTemplate2Dept> findAllTemplate2Dept() {
        return companyTemplate2DeptDao.findAllTemplate2Dept();
    }

    /**
     * 更改模块对应部门
     * @param template
     * @param depts
     * @return int
     */
    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int updateTemplate2Dept(CompanyTemplate template, List<Dept> depts) {
        return companyTemplate2DeptDao.updateTemplate2Dept(template, depts);
    }

    /**
     * 根据模板删除模板对应部门
     * @param template
     * @return int
     */
    @Override
    @Transactional(isolation = Isolation.REPEATABLE_READ,propagation = Propagation.REQUIRED,rollbackFor = Exception.class)
    public int deleteTemplate2Dept(CompanyTemplate template) {
        return companyTemplate2DeptDao.deleteTemplate2Dept(template);
    }


}
